package com.jdzy.student.controller;

import com.jdzy.model.common.vos.ResultA;
import com.jdzy.model.common.vos.ResultCodeEnum;
import com.jdzy.student.service.SysRoleService;
import com.jdzy.model.teacher.pojos.SysRole;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Map;

@RestController
@Slf4j
@Api(value = "角色的controller类")
@CrossOrigin(allowCredentials = "true" , allowedHeaders = "*")
@RequestMapping(value = "/api/system/sysRole")
public class SysRoleController {
    @Autowired
    private SysRoleService sysRoleService ;
    //查询所有角色
    @GetMapping(value = "/findAllRoles/{userId}")
    public ResultA<Map<String , Object>> findAllRoles(@PathVariable(value = "userId") Long userId) {
        Map<String, Object> resultMap = sysRoleService.findAllRoles(userId);
        return ResultA.build(resultMap , ResultCodeEnum.SUCCESS)  ;
    }
    //保存用户的信息
    @PostMapping(value = "/saveSysRole")
    public ResultA saveSysRole(@RequestBody SysRole SysRole) {
        sysRoleService.save(SysRole) ;
        return ResultA.build(null , ResultCodeEnum.SUCCESS) ;
    }
    //修改用户信息
    @PostMapping(value = "/updateSysRole")
    public ResultA updateSysRole(@RequestBody SysRole sysRole) {
        // 调用服务层更新方法
        sysRoleService.updateSysRole(sysRole);
        // 返回结果
        return ResultA.ok();
    }
    //删除用户信息
    @DeleteMapping(value = "/deleteById/{roleId}")
    public ResultA deleteById(@PathVariable(value = "roleId") Long roleId) {
        sysRoleService.removeById(roleId);
        return ResultA.build(null, ResultCodeEnum.SUCCESS);
    }
}
